package cn.tedu._04mybatis;

import cn.tedu._04mybatis.mapper.WeiboMapper;
import cn.tedu._04mybatis.pojo.entity.User;
import cn.tedu._04mybatis.pojo.entity.Weibo;
import cn.tedu._04mybatis.vo.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author Justin Parker
 * @Date 2024/8/3 0003 17:50
 * @Version 1.0
 */
@SpringBootTest
public class WeiboTexts {

    @Autowired
    private WeiboMapper weiboMapper;
    @Test
    void contextLoads() {
        Weibo weibo = new Weibo();
        weibo.setId(205L);
        weibo.setContent("微博就是个女厕所");
        weibo.setCreated(new Date());
        weibo.setUserId(100L);
        int i =weiboMapper.insertWeibo(weibo);
        System.out.println("添加了"+i+"条数据");
    }

    @Test
    void testUpdate(){
        Weibo weibo = new Weibo();
        weibo.setId(205L);
        weibo.setContent("微博就是个女厕所");
        weibo.setCreated(new Date());
        weibo.setUserId(102L);
        int i =weiboMapper.updateWeibo(weibo);
        System.out.println("修改了"+i+"条数据");
    }

    @Test
    void testDelete(){
        Weibo weibo = new Weibo();
        weibo.setId(208L);
        int i =weiboMapper.deleteWeibo(weibo);
        System.out.println("删除了"+i+"条数据");
    }

    @Test
    void testSelect(){
        Weibo weibo = weiboMapper.selectWeibo(200L);
        System.out.println(weibo);
    }

    @Test
    void testSelectById(){
        List<Weibo> weibos = weiboMapper.selectWeiboByUserId(101L);
        System.out.println(weibos);
    }

    @Test
    void testSelectByIdVo1(){
        WeiboVo1 weibos = weiboMapper.selectWeiboVo1(209L);
        System.out.println(weibos);
    }

    @Test
    void testSelectByIdVo2(){
        List<WeiboVo2> weibos = weiboMapper.selectWeiboVo2();
        System.out.println(weibos);
    }

    @Test
    void dynamicUpdate(){
        Weibo weibo = new Weibo();
        weibo.setId(200L);
        weibo.setContent("微博就是个女厕所");
        weibo.setCreated(new Date());

        int i = weiboMapper.dynamicUpdate(weibo);
        System.out.println("修改了"+i+"条数据");
    }

    @Test
    void deleteWeiboByIds1(){
        Long[] ids = {205L,210L};
        int i = weiboMapper.deleteWeiboByIds1(ids);
        System.out.println("删除了"+i+"条数据");
    }

    @Test
    void deleteWeiboByIds2(){
        ArrayList<Long> ids = new ArrayList<>();
        ids.add(205L);
        ids.add(209L);
        ids.add(210L);
        int i = weiboMapper.deleteWeiboByIds2(ids);
        System.out.println("删除了"+i+"条数据");
    }

    @Test
    void countWeibo(){
        int i = weiboMapper.countWeibo();
        System.out.println("共有"+i+"条微博");
    }

    @Test
    void selectMapperTest(){
       ResultMapVO1 i = weiboMapper.selectMapper1(200L);
        System.out.println(i);
    }

    @Test
    void selectMapperTest2(){
        ResultMapVO2 i = weiboMapper.selectMapper2(101L);
        System.out.println(i);
    }

    @Test
    void selectMapperTest3(){
        ResultMapVO3 i = weiboMapper.selectMapper3(201L);
        System.out.println(i);
    }

    @Test
    void selectMapperTest4(){
        ResultMapVO4 i = weiboMapper.selectMapper4(201L);
        System.out.println(i);
    }
}
